//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "CUrlLbl.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck est utilisé est utilisé pour être sûr que les composants créés n'ont
// aucune fonction virtuelle pure.
//
static inline void ValidCtrCheck(CUrlLabel *)
{
  new CUrlLabel(NULL);
}
//---------------------------------------------------------------------------
__fastcall CUrlLabel::CUrlLabel(TComponent* Owner)
  : TCustomLabel(Owner)
{
  Cursor            = crHandPoint;
  Font->Color       = clNavy;
  Font->Style       = Font->Style << fsUnderline;
  m_eHighlightColor = clBlue;
  m_bMouseEnter     = false;
  Url               = "http://www.eic.fr";
}
//---------------------------------------------------------------------------
void __fastcall CUrlLabel::CMMouseEnter( TMessage &Message)
{
  TCustomLabel::Dispatch( &Message);
  m_bMouseEnter = true;
  m_eSaveColor  = Font->Color;
  Font->Color   = m_eHighlightColor;
}
//---------------------------------------------------------------------------
void __fastcall CUrlLabel::CMMouseLeave( TMessage &Message)
{
  TCustomLabel::Dispatch( &Message);
  Font->Color   = m_eSaveColor;
  m_bMouseEnter = false;
}
//---------------------------------------------------------------------------
void __fastcall CUrlLabel::SetHighLightColor( TColor eColor)
{
  m_eHighlightColor = eColor;
  if( m_bMouseEnter)
    Font->Color = m_eHighlightColor;
}
//---------------------------------------------------------------------------
void __fastcall CUrlLabel::SetUrl( const AnsiString strUrl)
{
  bool bCaptionIsEmpty = (( m_strUrl==Caption) || Caption.IsEmpty());

  m_strUrl = strUrl;
  if( bCaptionIsEmpty) Caption = m_strUrl;
}
//---------------------------------------------------------------------------
void __fastcall CUrlLabel::MouseDown( TMouseButton Button, TShiftState Shift, int X, int Y)
{
  TCustomLabel::MouseDown( Button, Shift, X, Y);

  ::ShellExecute( NULL, "open", Url.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
namespace Curllbl
{
  void __fastcall PACKAGE Register()
  {
     TComponentClass classes[1] = {__classid(CUrlLabel)};
     RegisterComponents("EIC Ctrlstd", classes, 0);
  }
}
//---------------------------------------------------------------------------
